<template>
    <div style="padding-left:20px">
         <el-table height="600"
    :data="tableData"
    style="width: 100%">
    <el-table-column  
      label="日期"
      width="180">
      <template slot-scope="scope" >
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px;">{{ scope.row.createtime }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="标题"
      width="180">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>标题: {{ scope.row.title }}</p>
          <p>预览: {{ scope.row.content }}</p>
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.title }}</el-tag>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row.id)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
    </div>
</template>
<script>
export default {
    data() {
      return {
        tableData: []
      }
    },
    methods: {
      handleEdit(index, id) {

          console.log("1230")
        
       this.$router.push({
					name: 'editor',
					params: {
						'id': id
					}
				});

      },
      handleDelete(index, id) {
let c = this;

      this.$confirm('此操作将永久删除该博客, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        
        .then(() => {



			 this.$http.post("/api/blog/del",{id},{emulateJSON:true}).then(res => {
	  
	  console.log(res.data)
	  return res.data

    })  
      .then((res) =>{
            if(res.erron == 0){
              
             this.$message({
            type: 'success',
            message: '删除成功!'
          });

 c.$http.get("/api/blog/getsum").then(res => {
	  
	  
	  c.tableData = res.data.data.data;

    });
            }
            else{
              alert("请先登录")
            }

      })


          
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });

    

      }
    },
    created(){
	let c = this;
			 this.$http.get("/api/blog/getsum").then(res => {
	  
	  
	  c.tableData = res.data.data.data;

    });
    }
}
</script>

<style lang="css">
    
</style>